//参考  https://www.cnblogs.com/accordion/p/10450952.html
const mydb=require('./model/db');
const Koa = require('koa');
const Router = require('koa-router');


let app = new Koa();
let router = new Router();
router.get('/', async (ctx, next) => {
    ctx.body = {
        status: 'ok',
        result: "hello server start ok!",
    };
});

router.get('/get-all-plans', async (ctx, next) => {
    let ret = await mydb.query("select *  from plan limit 20");
    ctx.set("Access-Control-Allow-Origin", '*') ;
    // ctx.set("Access-Control-Allow-Methods" , "GET, POST, DELETE, PUT, OPTIONS, TRACE, HEAD, PATCH");
    // ctx.set("Access-Control-Allow-Headers" ,"Content-Type") ;
    ctx.body = {
        status: 'ok',
        result: ret,
    };
});

app
  .use(router.routes())
  .use(router.allowedMethods())
  .listen(8000);